package com.ysdzz.hadoop.wordcount;

import java.io.IOException;
import java.util.Iterator;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class WordCountReducer extends Reducer<Text, LongWritable, Text, LongWritable> {

	@Override
	protected void reduce(Text arg0, Iterable<LongWritable> arg1,
			Reducer<Text, LongWritable, Text, LongWritable>.Context arg2) throws IOException, InterruptedException {
		
		LongWritable counter = new LongWritable();
		Iterator<LongWritable> it = arg1.iterator();
		while (it.hasNext()) {
			counter.set(counter.get()+it.next().get());
		}
		arg2.write(arg0, counter);
	}

	
	
}
